#include "processor.h"

Processor::Processor(void)
{
  control = new LinkControl;
}

Processor::~Processor(void)
{
  delete control;
}

void Processor::SetAddress(unsigned int address)
{
  uint32_PhysicalAddress = address;
}

void Processor::SetPixel(bool value)
{
  if(value)
  {
    uint32_FinalLabel = uint32_PhysicalAddress;
    control->SetHostAddress(uint32_PhysicalAddress);
  }

  b_Pixel = value;
}

void Processor::SetPhysicalLinks(bool * physicalLinks[8])
{
  control->SetLinkToNeighbor(LinkControl::NORTH,      physicalLinks[0]);
  control->SetLinkToNeighbor(LinkControl::NORTHEAST,  physicalLinks[1]);
  control->SetLinkToNeighbor(LinkControl::NORTHWEST,  physicalLinks[2]);
  control->SetLinkToNeighbor(LinkControl::SOUTH,      physicalLinks[3]);
  control->SetLinkToNeighbor(LinkControl::SOUTHEAST,  physicalLinks[4]);
  control->SetLinkToNeighbor(LinkControl::SOUTHWEST,  physicalLinks[5]);
  control->SetLinkToNeighbor(LinkControl::EAST,       physicalLinks[6]);
  control->SetLinkToNeighbor(LinkControl::WEST,       physicalLinks[7]);
  
  control->SetHostAddress(0x80000000);
}

void Processor::PrintActiveLinks(void)
{
  control->PrintActiveLinks();
}

void Processor::ClockProcessor(void)
{
  control->ClockLinkControl();
}

bool Processor::ProcessorComplete(void)
{
  // exit if link is not a black pixel
  if(!b_Pixel)
  {
    return true;
  }


  if(control->AreAllLinksComplete())
  {
    uint32_FinalLabel = control->GetLinkControlFinalLabel();
    return true;
  }
  
  return false;

}

unsigned int Processor::GetFinalLabel(void)
{
  return uint32_FinalLabel;
}

bool Processor::GetPixelValue(void)
{
  return b_Pixel;
}

bool * Processor::GetSouthLink(void)
{
  return control->GetPhysicalLinkAddress(LinkControl::SOUTH);
}

bool * Processor::GetSouthEastLink(void)
{
  return control->GetPhysicalLinkAddress(LinkControl::SOUTHEAST);
}

bool * Processor::GetSouthWestLink(void)
{
  return control->GetPhysicalLinkAddress(LinkControl::SOUTHWEST);
}

bool * Processor::GetEastLink(void)
{
  return control->GetPhysicalLinkAddress(LinkControl::EAST);
}

